package edu.response;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.nio.Buffer;

/**
 * 在线看图片
 */
@WebServlet("/lookPicture")
public class LookPicture extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setHeader("Content-Type","image/jpg; charset=utf-8");
        //PrintWriter writer = response.getWriter();
        ServletOutputStream outputStream = response.getOutputStream();
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\TIM文件\\Java后端开发学习路线-高清版.jpg"));
        int len;
        byte[] buffer = new byte[1024];
        while ((len=bis.read(buffer))!=-1){
            outputStream.write(buffer,0,len);
        }
        outputStream.flush();
        bis.close();
        outputStream.close();
    }
}
